using System.Xml;
using System.Collections.Generic;
using System;

using GSN.Mail.Messages;

namespace GSN.Rules
{
    class RulesManager
    {
        //IRule[] rules = null;

        public RulesManager()
        {
            //reloadRules();
        }

        /*
        public void reloadRules()
        {
            
        }
         */

        public bool applyGenRules()
        {
            IRule[] rules = RulesConfigManager.loadRules(GSNConfig.getRulesNodes());

            if (rules == null)
                return true;

            bool result = true;

            foreach (IRule rule in rules)
            {
                if (rule is IGenRule)
                {
                    if (!((IGenRule)rule).apply())
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;
        }

        public bool applyMsgRules(Message msg)
        {
            IRule[] rules = RulesConfigManager.loadRules(GSNConfig.getRulesNodes());

            if (rules == null)
                return true;

            bool result = true;

            foreach (IRule rule in rules)
            {
                if (rule is IMsgRule)
                {
                    if (!((IMsgRule)rule).apply(msg))
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;

        }
    }

}
